﻿using System;
using System.Web.UI;

namespace TestHarness
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                GridView1.DataSource = MTC.Business.Driver.Driver.GetDrivers();
                GridView1.DataBind();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            txtDriverId.Text = string.Empty;
            txtFirstName.Text = string.Empty;
            txtLastName.Text = string.Empty;
            txtLicience.Text = string.Empty;
            txtMobile1.Text = string.Empty;
            txtMobile2.Text = string.Empty;
            txtPostcode.Text = string.Empty;
            txtState.Text = string.Empty;
            txtStreet1.Text = string.Empty;
            txtStreet2.Text = string.Empty;
            txtSuburb.Text = string.Empty;
            txtTitle.Text = string.Empty;
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            MTC.Common.DTO.Driver driver = new MTC.Common.DTO.Driver();
            driver.FirstName = txtFirstName.Text;
            driver.LastName = txtLastName.Text;
            driver.Licience = txtLicience.Text;
            driver.Mobile1 = txtMobile1.Text;
            driver.Mobile2 = txtMobile2.Text;
            driver.Postcode = txtPostcode.Text;
            driver.State = txtPostcode.Text;
            driver.Street1 = txtStreet1.Text;
            driver.Street2 = txtStreet2.Text;
            driver.Suburb = txtSuburb.Text;
            driver.Title = txtTitle.Text;

            MTC.Business.Driver.Driver.AddDriver(driver);

            Button1_Click(null, null);
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            MTC.Common.DTO.Driver driver = new MTC.Common.DTO.Driver();
            driver.DriverId = Convert.ToInt32(txtDriverId.Text);
            driver.FirstName = txtFirstName.Text;
            driver.LastName = txtLastName.Text;
            driver.Licience = txtLicience.Text;
            driver.Mobile1 = txtMobile1.Text;
            driver.Mobile2 = txtMobile2.Text;
            driver.Postcode = txtPostcode.Text;
            driver.State = txtPostcode.Text;
            driver.Street1 = txtStreet1.Text;
            driver.Street2 = txtStreet2.Text;
            driver.Suburb = txtSuburb.Text;
            driver.Title = txtTitle.Text;

            MTC.Business.Driver.Driver.UpdateDriver(driver);

            Button1_Click(null, null);
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            int driverId;
            driverId = Convert.ToInt32(txtDriverId.Text);
            MTC.Business.Driver.Driver.DeleteDriver(driverId);

            Button1_Click(null, null);

        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            int driverId;
            MTC.Common.DTO.Driver driver;
            driverId = Convert.ToInt32(txtDriverId.Text);

            driver = MTC.Business.Driver.Driver.GetDriver(driverId);
            
            txtDriverId.Text = Convert.ToString(driver.DriverId);
            txtFirstName.Text = driver.FirstName;
            txtLastName.Text = driver.LastName;
            txtLicience.Text = driver.Licience;
            txtMobile1.Text = driver.Mobile1;
            txtMobile2.Text = driver.Mobile2;
            txtPostcode.Text = driver.Postcode;
            txtState.Text = driver.State;
            txtStreet1.Text = driver.Street1;
            txtStreet2.Text = driver.Street2;
            txtSuburb.Text = driver.Suburb;
            txtTitle.Text = driver.Title;

        }
    }
}
